function getBookHtml(book) {
    let bookItemHtml = ""

    for (let i = 0; i < book.items.length; i++) {
        let item = book.items[i]
        let str = ""
        if (item.borrow) {
            str = `
                                <div class="real-book-item">
                                    <span>${item.itemId}</span>
                                    <span>${item.endTime} 应还</span>
                                </div>
                                `
        } else {
            str = `
                                <div class="real-book-item">
                                    <span>${item.itemId}</span>
                                    <button type="button" onclick="borrowBook(${item.itemId})" class="layui-btn layui-btn-xs">点击借阅</button>
                                </div>
                            `
        }

        bookItemHtml += str
    }

    let html = `
<div id="layer_notice">
    <div class="book-base-info">
        <div class="book-cover">
            <img src="${book.cover}" alt="">
        </div>
        <div class="book-info">
            <div class="book-name">${book.name}</div>
            <div class="book-author">${book.author}</div>
            <div class="book-publisher">${book.publisher}</div>
            <div class="book-pub-time">${book.pubTime}</div>
        </div>
    </div>
    <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
        <ul class="layui-tab-title">
            <li class="layui-this">馆藏位置</li>
            <li>内容简介</li>
            <li>作者简介</li>
        </ul>
        <div class="layui-tab-content" style="height: 100px;">
            <!--                位置信息-->
            <div class="layui-tab-item layui-show">
                <div class="local-box">6楼46行A面3架</div>
                <div class="real-book-list">
                    ${bookItemHtml}
                </div>
            </div>
            <!--                位置信息-->

            <!--                内容简介-->
            <div class="layui-tab-item">
                <div style="padding-left: 5px;font-weight: 700;margin-bottom: 5px">内容简介</div>
                <p class="book-desc">${book.description}</p>
            </div>
            <div class="layui-tab-item">
                <div style="padding-left: 5px;font-weight: 700;margin-bottom: 10px">作者简介</div>
                <div class="author-name">${book.author}</div>
                <p class="author-desc">${book.authorDesc}</p>
            </div>
        </div>
    </div>
</div>
                    `

    return html;

}

function borrowBook(itemId) {
    $$.ajax({
        type: "post",
        url: "/borrow/" + itemId,
        dataType: "json",
        contentType: "application/json;charset=UTF-8",
        success: function (data) {
            if (data.code === 200) {
                layer.msg("借阅成功", {icon: 1});
                setTimeout(() => {
                    location.reload();
                }, 1000)
            } else {
                layer.msg(data.msg, {icon: 5});
            }
        }
    });
}